package com.china08.yxyapi.api.manage.sch.platform.xiaoben.auth;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.db.lessons.YxyLessonsSchoolLessonAuth;
import com.china08.yxyapi.model.YxyApiPageReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.db.YxyLessonsSchoolLessonAuthRepository;

import io.swagger.annotations.ApiOperation;

@CrossOrigin
@RestController
public class KeChengAuthDelController extends YxyApiBaseController {

    @Autowired
    YxyLessonsSchoolLessonAuthRepository authRepository;

    @ApiOperation("")
    @RequestMapping(value = "/api_yw/manage/sch/xiaoben/auth/kecheng/del", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public void process(HttpServletRequest request, HttpServletResponse response, @RequestBody ReqModel reqModel) {
        String lessonId = reqModel.lessonId;
        String userId = reqModel.userId;

        YxyLessonsSchoolLessonAuth yxyLessonsSchoolLessonAuth = authRepository.findByLessonIdAndUserId(lessonId, userId);
        if (null != yxyLessonsSchoolLessonAuth) {
            authRepository.delete(yxyLessonsSchoolLessonAuth);
        }
    }

    public static class ReqModel extends YxyApiPageReqModel {
        public String lessonId;
        public String userId;

        @Override
        public void autoCheck() {
            Assert.isTrue(StringUtils.isNotBlank(lessonId), "课程为空");
            Assert.isTrue(StringUtils.isNotBlank(userId), "用户为空");
        }
    }

    public static class RespModel extends YxyApiRespModel {
    }
}
